// https://leetcode.cn/problems/day-of-the-week/
// Created by ade on 2022/11/1.
// 1971-01-01 周五
#include <iostream>
#include <vector>
#include <string>

using namespace std;

class Solution {
public:
    // 提示： 1971-01-01 周五
    string dayOfTheWeek(int day, int month, int year) {
        vector<int> months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        vector <string> desc = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
        int c = 0;
        for (int i = 1971; i < year; i++) {
            c += 365;
            if (isLeapYear(i)) c++;
        }
        if (isLeapYear(year)) months[1]++;
        for (int i = 0; i < month - 1; i++) c += months[i];
        c += day;
        return desc[(c % 7 + 4) % 7];
    }

    bool isLeapYear(int year) {
        return year % 400 == 0 || year % 4 == 0 && year % 100 != 0;
    }
};

int main() {
    Solution so;
    cout << so.dayOfTheWeek(31, 8, 2019);
    return 0;
}